package com.example.programexpert

import android.os.Bundle
import android.view.KeyEvent
import android.widget.Button
import android.widget.LinearLayout
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.enableEdgeToEdge
import android.graphics.Color // 导入 View 体系的 Color 类

class MainActivity : ComponentActivity() {

    val expert = ProgramExpert()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)

        val spinner = findViewById<Spinner>(R.id.spinner)
        val button = findViewById<Button>(R.id.button)
        val textView = findViewById<TextView>(R.id.textView)

        button.setOnClickListener {
            textView.text = expert.getLanguage(spinner.selectedItem.toString())
        }

        val dynamicTexts: LinearLayout = findViewById(R.id.dynamic_texts)
        val buttonAddText: Button = findViewById(R.id.button2)

        buttonAddText.setOnClickListener {
            val count = dynamicTexts.childCount + 1
            val dynamicText = TextView(this).apply {
                text = "I love Android!!!!$count\n"
                textSize = 16f
                setTextColor(Color.BLACK) // 现在可正确引用 View 体系的 BLACK
                setBackgroundColor(Color.parseColor("#87CEEB")) // 正确解析十六进制颜色
                setPadding(16, 12, 16, 12)
            }
            dynamicTexts.addView(dynamicText)
        }
    }
}